package 剑指offer;

import java.util.Arrays;
import java.util.Scanner;

public class Check {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] arrs = new String[n];
        for (int i = 0; i < n; i++) {
            String str = sc.next();
            arrs[i] = str;
        }
        System.out.println(Arrays.toString(arrs));
        getCheck(arrs);
        System.out.println(Arrays.toString(arrs));

    }

    public static void getCheck(String[] arrs) {
        for (int i = 0; i < arrs.length; i++) {
            arrs[i] = String.valueOf(check(new StringBuilder(arrs[i])));

        }
    }

    public static StringBuilder check(StringBuilder stringBuilder) {
        if (stringBuilder == null) {
            return null;
        }
        int preCount = 1;   //前面一个
        int nextCount = 1; //后面一个
        boolean flag = true;
        boolean have = false;
        //  int count = 0;
        for (int i = 0; i < stringBuilder.length() - 1; i++) {
            if (stringBuilder.charAt(i) == stringBuilder.charAt(i + 1)) {
                if (flag == true) {
                    preCount++;
                } else {
                    nextCount++;
                }
                if (preCount == 3) { //到达三个，删除
                    stringBuilder.delete(i, i + 1);
                    i--;
                    preCount--;
                    continue;
                }
                if (preCount == 2 && nextCount == 2) {
                    stringBuilder.delete(i, i + 1); //如果前面二个，后面两个
                    i--;
                    nextCount--;
                    continue;

                }
            } else {

                if (preCount==2&&!flag) { //当不相等时，重新初始化preCount 和 nextCount , 1123,
                    preCount = 1;
                    nextCount = 1;
                    flag =true;
                    continue;
                }

                if (preCount == 2) {
                    flag = false;


                }
            }


        }
        return stringBuilder;
    }
}
